<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">
      <el-row :gutter="32">
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <bar-chart :title="barData.title" :datas="barData.datas" :legendNames="barData.names" />
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <pie-chart :title="eTypeCountData.title" :datas="eTypeCountData.datas" :legendNames="eTypeCountData.names" />
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <pie-chart :title="pieData.title" :datas="pieData.datas" :legendNames="pieData.names" />
          </div>
        </el-col>
      </el-row> 


      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <line-chart :chart-data="lineChartData" />
      </el-row>
    </div>
  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
//import LineChart from './dashboard/LineChart'
import PieChart from '@/components/Echarts/PieChart'
import RadarChart from '@/components/Echarts/RadarChart'
import BarChart from '@/components/Echarts/BarChart'
import LineChart from '@/components/Echarts/LineChart'
import iotStats from '../api/iot/iotStats'
import EtypeGroup from './iot/stats/EtypeGroup'
import ErealState from './iot/stats/ErealState'


export default {
  name: 'Dashboard',
  components: {
    PanelGroup,
    LineChart,
    RadarChart,
    EtypeGroup,
    ErealState,
    BarChart,
    PieChart,
    iotStats
  },
  data() {
    return {
      lineChartData: [],
      eTypeCountData: {
        datas: [],
        names: [],
        title: "设备类型"
      },
      pieData: {
        datas: [],
        names: [],
        title: "设备状态"
      },
      barData: {
        datas: [],
        names: [],
        title: "设备状态"
      }
    }
  },
  mounted: function() {
    this.initPieData()
  },
  methods: {
    initPieData() {
      iotStats.realStateCount(1).then(res => {
        this.pieData.datas = res.datas;
        this.pieData.names = res.names;
      })

      iotStats.etypeGroupCount(1).then(res => {
        this.eTypeCountData.datas = res.datas;
        this.eTypeCountData.names = res.names;

        this.barData.datas = res.datas;
        this.barData.names = res.names;        
      })

      iotStats.getEquipData(7, '2021-05-05', '2021-05-06').then(res => {
        debugger

        let equipHisData = {}
        equipHisData.xDatas = res.TIMES
        equipHisData.datas = res.VALUES
        equipHisData.code = "e7"

        this.lineChartData.push(equipHisData)
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .github-corner {
      position: absolute;
      top: 0;
      border: 0;
      right: 0;
    }

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
